#!/usr/bin/python3
# -*- coding:utf-8 -*-
# @Time : 2018/9/18 下午2:28
# @Author : Desunire
# @projectname : bzShop
# @name: views_base


from django.views.generic.base import View

from  good.models import Goods

class GoodListView(View):
    def get(self,request):
        """
        通过django的view实现商品列表页
        :param request:
        :return:
        """
        json_list = []
        goods = Goods.objects.all()[:10]
        # for good in goods:
        #     json_dict = {}
        #     json_dict["name"] = good.name
        #     json_dict["category"] =  good.category.name
        #     json_dict["market_price"] = good.market_price
        #     json_list.append(json_dict)
        from django.http import HttpResponse,JsonResponse
        import json
        from django.core import serializers
        json_data = serializers.serialize("json",goods)
        json_data = json.loads(json_data)
        # return HttpResponse(json.dumps(json_data),content_type="application/json")
        return JsonResponse(json_data,safe=False)